//
// Created by v on 24-5-15.
//

#include <getopt.h>
#include <assert.h>
#include <unistd.h>

#include "control_remote_service.h"
#include "utils/rt_print.h"
#include "cm_thread_task_manager.h"

void test_control_service()
{
    CMThreadTaskManager taskManager;
    taskManager.start();

    ControlRemoteService controlRemoteService;
    int ret = controlRemoteService.start("192.168.5.187", 7799);
    if (ret < 0)
    {
        rterror("Error of start service [%d]", ret);
        return;
    }
    std::string data = R"({"cmd":"report_lock","args":{}})";
    int i = 0;
    std::string recvData;
    int last_time = time(NULL);
    while (i++ < 10000000)
    {
        controlRemoteService.doCycle();
        if (time(NULL) - last_time > 5)
        {
            last_time = time(NULL);
            controlRemoteService.sendData(data);
        }
        usleep(10000);
    }
    rtinfo("done");
}

int main(int argc, char **args)
{
    rt_print_init(RT_PRINT_ALL, RT_PRINT_STYLE_ALL, 1, "clientOne");
    rtdebug("build_at [%s: %s]\n", __DATE__, __TIME__);

    test_control_service();
    return 0;
}
